//
//  WBDiscoverSearchView.swift
//  WBWeiBo
//
//  Created by 王斌 on 16/7/12.
//  Copyright © 2016年 王斌. All rights reserved.
//

import UIKit

class WBDiscoverSearchView: UIView ,UITextFieldDelegate{

    @IBOutlet weak var textFiledRight: NSLayoutConstraint!


    @IBOutlet weak var cancelButton: UIButton!
    
    
    @IBOutlet weak var textFiled: UITextField!
    
    
    //  加载 xib
    class func searchView() -> WBDiscoverSearchView {
        
        return UINib(nibName: "WBDiscoverView", bundle: nil).instantiateWithOwner(nil, options: nil).last! as! WBDiscoverSearchView
    }
    
    
   
    
    @IBAction func cancelAction(sender: AnyObject) {
        //  取消第一响应
        textFiled.resignFirstResponder()
        textFiledRight.constant = 0
        
        UIView.animateWithDuration(0.24) { () -> Void in
            self.layoutIfNeeded()
        }
    }
    
    // MARK: -- UITextFieldDelegate 代理
    func textFieldDidBeginEditing(textField: UITextField) {
        
        textFiledRight.constant = cancelButton.width
        
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
    }
}
